package com.pig4cloud.pig.bzg.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.bzg.entity.WzNoticeAnnouncementEntity;
import com.pig4cloud.pig.bzg.service.WzNoticeAnnouncementService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 通知公告表
 *
 * @author pig
 * @date 2025-07-30 09:35:17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/wzNoticeAnnouncement" )
@Tag(description = "wzNoticeAnnouncement" , name = "通知公告表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class WzNoticeAnnouncementController {

    private final  WzNoticeAnnouncementService wzNoticeAnnouncementService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param wzNoticeAnnouncement 通知公告表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getWzNoticeAnnouncementPage(@ParameterObject Page page, @ParameterObject WzNoticeAnnouncementEntity wzNoticeAnnouncement) {
        return R.ok(wzNoticeAnnouncementService.selectWzNoticeAnnouncementList
				(page, wzNoticeAnnouncement));
    }


    /**
     * 通过id查询通知公告表
     * @param noticeId id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{noticeId}" )
    public R getById(@PathVariable("noticeId" ) Long noticeId) {
        return R.ok(wzNoticeAnnouncementService.getById(noticeId));
    }

    /**
     * 新增通知公告表
     * @param wzNoticeAnnouncement 通知公告表
     * @return R
     */
    @Operation(summary = "新增通知公告表" , description = "新增通知公告表" )
    @SysLog("新增通知公告表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('bzg_wzNoticeAnnouncement_add')" )
    public R save(@RequestBody WzNoticeAnnouncementEntity wzNoticeAnnouncement) {
        return R.ok(wzNoticeAnnouncementService.save(wzNoticeAnnouncement));
    }

    /**
     * 修改通知公告表
     * @param wzNoticeAnnouncement 通知公告表
     * @return R
     */
    @Operation(summary = "修改通知公告表" , description = "修改通知公告表" )
    @SysLog("修改通知公告表" )
    @PutMapping
    public R updateById(@RequestBody WzNoticeAnnouncementEntity wzNoticeAnnouncement) {
        return R.ok(wzNoticeAnnouncementService.updateById(wzNoticeAnnouncement));
    }

    /**
     * 通过id删除通知公告表
     * @param ids noticeId列表
     * @return R
     */
    @Operation(summary = "通过id删除通知公告表" , description = "通过id删除通知公告表" )
    @SysLog("通过id删除通知公告表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(wzNoticeAnnouncementService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param wzNoticeAnnouncement 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    public List<WzNoticeAnnouncementEntity> export(WzNoticeAnnouncementEntity wzNoticeAnnouncement,Long[] ids) {
        return wzNoticeAnnouncementService.list(Wrappers.lambdaQuery(wzNoticeAnnouncement).in(ArrayUtil.isNotEmpty(ids), WzNoticeAnnouncementEntity::getNoticeId, ids));
    }
}